package com.itjeffrey.autocode.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itjeffrey.autocode.bo.ResInfoTbBO;
import com.itjeffrey.autocode.bo.req.ChangeAuthResBO;
import com.itjeffrey.autocode.bo.req.IsEnableBO;
import com.itjeffrey.autocode.entity.ResInfoTbEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 持久层接口
 * @author: admin
 * @date: 2021-03-28 12:35:25
 */
public interface ResInfoTbMapper extends BaseMapper<ResInfoTbEntity> {

    List<ResInfoTbEntity> queryResInfosByRoleId(@Param("roleId") Integer roleId, @Param("resType") String resType);

    List<ResInfoTbEntity> queryHasNotAuthrizeResources(@Param("roleId") Integer roleId);

    void changeAuthRes(@Param("labels") List<String> labels);

    void changeCancleAuthRes(@Param("labels") List<String> labels);

    void isEnable(IsEnableBO isEnableBO);

    @Insert("INSERT INTO role_res_tb(role_id, res_id) VALUES(#{roleId}, #{resId})")
    int insertAdminRoleRes(@Param("roleId") Integer adminRoleId, @Param("resId") Integer resId);

    @Delete("DELETE FROM role_res_tb WHERE res_id = #{resId}")
    int deleteRoleResInfosByResId(@Param("resId") Integer id);

    int batchInsertRoleRes(@Param("roleId") Integer roleId,
                         @Param("changeAuthList") List<ChangeAuthResBO> changeAuthList);

    //TODO 批量删除待处理
    int batchDeleteRoleRes(@Param("roleId")Integer roleId,
                          @Param("changeAuthList") List<ChangeAuthResBO> changeAuthList);

    @Delete("DELETE FROM role_res_tb WHERE role_id = #{roleId} AND res_id = #{resId}")
    int deleteRoleRes(@Param("roleId") Integer roleId, @Param("resId") Integer resId);
}
